package model;

import controller.MessageController;

import java.io.IOException;

public class Weapon extends Item {
    private int add_con;
    private int add_dex;
    private int add_str;
    private int add_wis;
    static int maxnum=5;

    @Override
    public String getDesc() {
        String tmp="";
        tmp+="名称:"+getName()+"\n";
        tmp+="数量:"+getNum()+"\n";
        tmp+="类型:"+getType()+"\n";
        if(add_con>0){
            tmp+="con:+"+getAdd_con()+"\n";
        }
        if(add_dex>0){
            tmp+="dex:+"+getAdd_dex()+"\n";
        }
        if(add_str>0){
            tmp+="str:+"+getAdd_str()+"\n";
        }
        if(add_wis>0){
            tmp+="wis:+"+getAdd_wis()+"\n";
        }
        tmp+="物品描述:"+desc+"\n";
        return tmp;
    }

    public Weapon(Weapon weapon){
        super(weapon.getNum(), weapon.getName(), weapon.getType(), weapon.getDesc(), weapon.getLocation());
        this.add_con=weapon.getAdd_con();
        this.add_dex=weapon.getAdd_dex();
        this.add_str=weapon.getAdd_str();
        this.add_wis=weapon.getAdd_wis();
    }

    public Weapon(int num, String name, String type, String desc,int add_con,int add_dex,int add_str,int add_wis,String location) {
        super(num, name, type, desc, location);
        this.add_con = add_con;
        this.add_dex = add_dex;
        this.add_str = add_str;
        this.add_wis = add_wis;
    }

    public boolean check(int x) {
        return x +num<= maxnum;
    }

    @Override
    public int getMaxnum() {
        return maxnum;
    }

    @Override
    public void use(Player p) throws IOException {
        if (this.have()){
            num=num-1;
            p.setCon(add_con+p.getCon());
            p.setDex(add_dex+p.getDex());
            p.setStr(add_str+p.getStr());
            p.setWis(add_wis+p.getWis());
            MessageController.showToPlayer(p,"装备成功。");
            MessageController.showToPlayer(p,p.getdesc());
        }else {
            MessageController.showToPlayer(p,"您没有此物品。");
        }
    }

    public int getAdd_con() {
        return add_con;
    }
    public void setAdd_con(int add_con) {
        this.add_con = add_con;
    }
    public int getAdd_dex() {
        return add_dex;
    }
    public void setAdd_dex(int add_dex) {
        this.add_dex = add_dex;
    }
    public int getAdd_str() {
        return add_str;
    }
    public void setAdd_str(int add_str) {
        this.add_str = add_str;
    }
    public int getAdd_wis() {
        return add_wis;
    }
    public void setAdd_wis(int add_wis) {
        this.add_wis = add_wis;
    }
}
